package com.kgc.ljp.InputStream;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;

public class FileInputStreamDemo {
    public static void main(String[] args)
            throws IOException {
        String file = "c:out.txt";
        InputStream in = new FileInputStream(file);
        int b;
        while((b=in.read())!=-1){//read()方法
            System.out.print(Integer.toHexString(b) + " ");
        }
        in.close();

        in = new FileInputStream(file);
        //in.available() 可以读取的数据个数，小文件一般是文件长度
        byte[] buf = new byte[in.available()];
        in.read(buf);//read(byte[] buf)方法重载
        in.close();
        for (byte c : buf) {
            System.out.print(Integer.toHexString(c & 0xff) + " ");
            // c & 0xff --->将16进制写成0xff的格式
            //ffffffd6---> d6
            //11111111 11111111 11111111 11010110  &对应相乘
            //00000000 00000000 00000000 11111111  0xff
            //00000000 00000000 00000000 11010110
        }
    }
}
